package com.chenss.dragonser.view;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.chenss.dragonser.R;
import com.chenss.dragonser.listener.OnMyDialogTwoListener;
import com.chenss.dragonser.utils.WidgetTools;

/**
 * 
 * 两个弹框的
 * 
 * @author xm
 */
public class XDialogTwo {
	OnMyDialogTwoListener twoListener;

	public XDialogTwo(OnMyDialogTwoListener twoListener) {
		this.twoListener = twoListener;
	}

	/**
	 * 弹出提示框
	 * @param context 上下文对象
	 * @param msg  展示的信息
	 * @param queding 确定按钮
	 * @param quxiao 取消按钮
	 * @param title 标题
	 * @param tag 用来标识那个地方的弹框
	 */
	public void showTwoDialog(Context context, String msg, String queding, String quxiao, String title,
			final int tag) {
		// TODO Auto-generated method stub
		final Dialog dialog = new Dialog(context, R.style.Dialog_image);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			dialog.setContentView(R.layout.xdg_two_bt);
		WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
		TextView textView = (TextView) dialog.findViewById(R.id.text_message);
		TextView tv_title = (TextView) dialog.findViewById(R.id.tv_title);

		Button btn_cancle = (Button) dialog.findViewById(R.id.btn_one);
		Button btn_submit = (Button) dialog.findViewById(R.id.btn_two);
		if (TextUtils.isEmpty(title)) {
			tv_title.setVisibility(View.GONE);
		} else {
			WidgetTools.setText(tv_title, title);
		}
		WidgetTools.setText(textView, msg);
		WidgetTools.setText(btn_cancle, quxiao);
		WidgetTools.setText(btn_submit, queding);

		Window dialogWindow = dialog.getWindow();
		dialogWindow.setGravity(Gravity.CENTER);
		if (!dialog.isShowing()) {
			dialog.show();
		}

		dialog.getWindow().setAttributes(params);

		btn_cancle.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				dialog.dismiss();
				twoListener.onCancleClick(tag);

			}
		});
		btn_submit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				dialog.dismiss();
				twoListener.onSubmitClick(tag);
			}
		});
	}
}
